package com.didispace.service.impl;

import com.didispace.dao.EBookMapper;
import com.didispace.domain.Ebook;
import com.didispace.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    private EBookMapper ebookMapperReader;

    private EBookMapper ebookMapperWriter;

    @Autowired
    public void setEbookMapperReader(EBookMapper ebookMapperReader) {
        this.ebookMapperReader = ebookMapperReader;
    }

    @Autowired
    public void setEbookMapperWriter(EBookMapper ebookMapperWriter) {
        this.ebookMapperWriter = ebookMapperWriter;
    }

    @Override
    public int save(Ebook ebook) {
        return this.ebookMapperWriter.insert(ebook);
    }

    @Override
    public int delete(Long id) {
        return this.ebookMapperWriter.delete(id);
    }

    @Override
    public int update(Long id, Ebook ebook) {
        return this.ebookMapperWriter.update(id, ebook);
    }

    @Override
    public Ebook findById(Long id) {
        return this.ebookMapperReader.findById(id);
    }

    @Override
    public Ebook findByName(String name) {
        return this.ebookMapperReader.findByName(name);
    }

    @Override
    public List<Ebook> findByNameLike(String name) {
        return this.ebookMapperReader.findByNameLike(name);
    }

    @Override
    public List<Ebook> findAll() {
        return this.ebookMapperReader.findAll();
    }
}
